export default function () {
  return {
    api: {
      insert: '',
      delete: '',
      updata: '',
      query: '',
      handler(data) {
        return data.reduce((result, value, index) => {
          const { dataMap = {}, stnm, hnnm } = value;
          const yearArr = Object.keys(dataMap);
          result.push({
            stnm,
            hnnm,
            index: index + 1,
            rowspan: yearArr.length + 1
          });
          yearArr.forEach(year => {
            result.push({ year, ...dataMap[year] })
          });
          return result;
        }, []);
      },
    },
    height: window.innerHeight - 200,
    size: 'mini',
    spanMethod(option) {
      const { row, column: { property } } = option
      const flag = ['index', 'stnm', 'hnnm'].includes(property)

      if (row.rowspan && flag) {
        return [row.rowspan, 1]
      }

      if (!flag) {
        if (row.rowspan) return [0, 0]
        return [1, 1]
      }

      return [0, 0]
    },
    columns: [
      { prop: 'index', label: '序号', align: 'center', width: 50, fixed: 'left' },
      { prop: 'stnm', label: '沟名', align: 'center', width: 100, fixed: 'left' },
      { prop: 'hnnm', label: '站名', align: 'center', width: 100, fixed: 'left' },
      { prop: 'year', label: '年份', align: 'center', width: 150 },
      {
        label: '月均流量', align: 'center',
        group: [
          { prop: '1', label: '一月', align: 'center', width: 90 },
          { prop: '2', label: '二月', align: 'center', width: 90 },
          { prop: '3', label: '三月', align: 'center', width: 90 },
          { prop: '4', label: '四月', align: 'center', width: 90 },
          { prop: '5', label: '五月', align: 'center', width: 90 },
          { prop: '6', label: '六月', align: 'center', width: 90 },
          { prop: '7', label: '七月', align: 'center', width: 90 },
          { prop: '8', label: '八月', align: 'center', width: 90 },
          { prop: '9', label: '九月', align: 'center', width: 90 },
          { prop: '10', label: '十月', align: 'center', width: 90 },
          { prop: '11', label: '十一月', align: 'center', width: 90 },
          { prop: '12', label: '十二月', align: 'center', width: 90 },
        ]
      },
      {
        label: '年最大', align: 'center',
        group: [
          { prop: '1', label: '流量', align: 'center', width: 90 },
          { prop: '2', label: '日期', align: 'center', width: 90 },
        ]
      },
      {
        label: '年最小', align: 'center',
        group: [
          { prop: '1', label: '流量', align: 'center', width: 90 },
          { prop: '2', label: '日期', align: 'center', width: 90 },
        ]
      },
      { prop: '1', label: '年均流量', align: 'center', width: 120 },
      { prop: '2', label: '年径流量', align: 'center', width: 120 }
    ],
    pagination: {
      total: 0,
      pageSize: 10,
      background: true,
      layout: 'total, prev, pager, next',
    }
  }
}